<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%String path = request.getContextPath(); %>

<div class="callout callout-left">
  <span class="callout-title text-muted">激活错误统计</span><!-- &nbsp;<span class="glyphicon glyphicon-question-sign"></span> -->
  <a class="btn btn-primary"   href="javascript:;" id="export_excel" style="margin-left: 35px;"><span class="glyphicon glyphicon-export">&nbsp;导出excel</span></a>
</div>

<div class="callout">
  <form class="form-inline"  >
      <div class="form-group">
        <label for="start_search">开始日期：</label>
        <div class='input-group'>
          <input type='text' class='form-control' id='start_search' name='start_search' placeholder='开始日期'/>
          <span class='glyphicon glyphicon-calendar input-group-addon' style='top: 0;'></span>
        </div>
      </div>
      <div class="form-group">
        <label for="end_search">结束日期：</label>
        <div class='input-group'>
          <input type='text' class='form-control' id='end_search' name='start_search' placeholder='结束日期'/>
          <span class='glyphicon glyphicon-calendar input-group-addon' style='top: 0;'></span>
        </div>
      </div>&nbsp;
    <button type="button" class="btn btn-primary" id="doSearch">
      <span class="glyphicon glyphicon-search">&nbsp;搜索</span>
    </button>&nbsp;&nbsp;&nbsp;
  </form>
</div>

<div class="callout callout-white">
<div class="table-responsive center-block" style="max-width: 550px;">
  <table class="table table-bordered" id="t_excel">
    <thead>
      <tr>
        <th>#</th>
        <th>错误代码</th>
      	<th>出现次数</th>
      </tr>
    </thead>
    <tbody id="err_content">
      
    </tbody>
  </table>
  </div>
</div>

<script>
require.config({
	urlArgs: 'v88',
	baseUrl: '<%=path %>/js',
	paths: {
		jquery: 'jquery-1.9.1.min',
		commmon: 'common',
		bootstrapswitch: 'bootstrap-switch.min'
	}
});
require(['jquery', 'common', 'bootstrapswitch'], function($, common) {
//console.log("激活错误统计模块载入");

var workspace = function() {

	var dataOpt;
	var errCodes;

	var init = function() {
		dataOpt = common.dataOpt;

    _datePiclerInit();
		_initTable();
    _doSearch();
		common.exportExcel("激活错误统计");
	}

  // 日期控件
  var _datePiclerInit = function() {
    [$("#start_search"), $("#end_search")].forEach(function(el) {
        $(el).val(new Date().Format("yyyy-MM-dd"));
        common.datePickerInit(el);
    })
  }

	// 初始化表格
	var _initTable = function() {
		errCodes = common.ajaxLoadData(dataOpt.errCodeOpt);
    dataOpt.errCodeOpt.data = {}

		var template = "<tr><th>#row#</th><td>#errCode#</td><td>#amount#</td></tr>";

		var row = 1;
		var html = "";
		for(var err in errCodes) {
			var thisT = template;
			thisT = thisT.replace(/#row#/g, row++).replace(/#errCode#/g, err)
				.replace(/#amount#/g, errCodes[err]);
			html += thisT;
		}
		$("#err_content").html(html);
	}

  // 搜索
  var _doSearch = function() {
    $("#doSearch").click(function() {
      var startDate = $("#start_search").val();
      var endDate = $("#end_search").val();

      if(startDate === endDate) {
          var addDate = new Date(endDate);
          addDate.setDate(addDate.getDate() + 1);
          endDate = addDate.Format("yyyy-MM-dd");
      }

      dataOpt.errCodeOpt.data = {
          // "dateSearch": $("#date_search").val()
          "startDate": startDate,
          "endDate": endDate
      }
      _initTable();
    });
  }

	return {
		init: init
	}
}();
	
$(function() { workspace.init(); });

});
requirejs.onError = function (err) {  
  console.error(err);
  if (err.requireType === 'timeout') {
      console.error('modules: ' + err.requireModules);
  }
  throw err;
}
</script>